home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume2 / basic / part2 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  45.0 KB

  1. From: ukma!david (David Herron, NPR Lover)
  2. Subject: A BASIC interpretor (Part 2 of 4)
  3. Newsgroups: mod.sources
  4. Approved: john@genrad.UUCP
  5.  
  6. Mod.sources:  Volume 2, Issue 24
  7. Submitted by: ukma!david (David Herron)
  8.  
  9.  
  10. #! /bin/sh
  11. # This is a shell archive, meaning:
  12. # 1. Remove everything above the #! /bin/sh line.
  13. # 2. Save the resulting text in a file.
  14. # 3. Execute the file with /bin/sh (not csh) to create the files:
  15. #    newbs/bsdefs.c
  16. #    newbs/bsdefs.h
  17. #    newbs/bsgram.y
  18. #    newbs/bslash.c
  19. #    newbs/bslib.c
  20. #    newbs/getplace.c
  21. #    newbs/gvadr.c
  22. #    newbs/makefile
  23. #    newbs/makefile.old
  24. #    newbs/mkop.c
  25. #    newbs/mkop.sh
  26. #    newbs/mksop.c
  27. #    newbs/num_ins.c
  28. #    newbs/op2.c
  29. #    newbs/operat.c
  30. #    newbs/scon_in.c
  31. # This archive created: Tue Jul 30 13:02:34 1985
  32. export PATH; PATH=/bin:$PATH
  33. if test ! -d 'newbs'
  34. then
  35.     echo shar: creating directory "'newbs'"
  36.     mkdir 'newbs'
  37. fi
  38. echo shar: extracting "'newbs/bsdefs.c'" '(1128 characters)'
  39. if test -f 'newbs/bsdefs.c'
  40. then
  41.     echo shar: will not over-write existing file "'newbs/bsdefs.c'"
  42. else
  43. sed 's/^X//' << \SHAR_EOF > 'newbs/bsdefs.c'
  44. /* bsdefs.c -- Actual definitions of all the variables.
  45.  *
  46.  * bsdefs.h only has the "extern's" of the things declared in here.
  47.  */
  48.  
  49. #include "bsdefs.h"
  50.  
  51.  
  52. /* Initial stuff for line number table.
  53.  *
  54.  * The line number table is a singly-linked list.  The head is "firstline",
  55.  * and the tail is "lastline".  The proper way to check for the end of the
  56.  * list is to compare it to LASTLINE.  Lastline points to itself in case
  57.  * I forget and code something differently (it also neatly ties up the end
  58.  * of the list).
  59.  */
  60.  
  61. #define LASTLINE    (struct line *)(&lastline)
  62.  
  63. struct line lastline = { &lastline,0077777,"",_nulline };
  64. struct line firstline = { &lastline,0,"",_nulline };
  65. struct line *curline = LASTLINE;
  66.  
  67.  
  68. /* Initial stuff for data statements.
  69.  *
  70.  * "dlist[]" holds pointers to lines that have data on them.  It is initialized
  71.  * in M_FIXUP.  "dlp" used to allocate entries from dlist[], it points to the
  72.  * first free entry.  "dlindx" points within the current data line to the next
  73.  * data item.
  74.  * "dtype" indicates the data type for the last data item.
  75.  */
  76.  
  77. struct line *dlist[DLSIZ];
  78. int dlp = 0,dlindx = 0, dtype = 0;
  79.  
  80. SHAR_EOF
  81. if test 1128 -ne "`wc -c < 'newbs/bsdefs.c'`"
  82. then
  83.     echo shar: error transmitting "'newbs/bsdefs.c'" '(should have been 1128 characters)'
  84. fi
  85. fi # end of overwriting check
  86. echo shar: extracting "'newbs/bsdefs.h'" '(4648 characters)'
  87. if test -f 'newbs/bsdefs.h'
  88. then
  89.     echo shar: will not over-write existing file "'newbs/bsdefs.h'"
  90. else
  91. sed 's/^X//' << \SHAR_EOF > 'newbs/bsdefs.h'
  92. /* bsdefs.h -- definition file for bs.
  93.  */
  94.  
  95. #include <stdio.h>
  96. #include <ctype.h>
  97.  
  98. /* 'Machine' status */
  99. extern int status;
  100. #define M_COMPILE    (1<<0)
  101. #define M_EXECUTE    (1<<1)
  102. #define M_INPUT        (1<<2)
  103. #define M_FIXUP        (1<<3)
  104. #define M_READ        (1<<4)
  105.  
  106. #define XMODE    (M_COMPILE|M_EXECUTE|M_INPUT|M_FIXUP|M_READ)
  107.  
  108.  
  109. /* line table. */
  110. #define LASTLINE    (struct line *)(&lastline)
  111.  
  112. struct line {
  113.     struct line *nextline;    /* next entry in list. */
  114.     int lnum;            /* its' number */
  115.     int (*list)();        /* its' definition */
  116.     char *text;            /* the original definition */
  117. };
  118.  
  119. extern struct line firstline,lastline,*curline;
  120.  
  121.  
  122. /* Variable types */
  123. #define Q_NRM    0    /* nice, ordinary variable */
  124. #define Q_ARY    1    /* array */
  125. #define Q_BF    2    /* builtin-function */
  126. #define Q_UFL    3    /* long user function */
  127. #define Q_UFS    4    /* short user function */
  128.  
  129.             /* in type part, a zero value is an undefined type. */
  130. #define T_INT    (1<<6)
  131. #define T_CHR    (2<<6)
  132. #define T_DBL    (3<<6)
  133. #define T_LBL    (4<<6)
  134.  
  135. #define T_QMASK        037        /* lower 5 bits for type qualifier */
  136. #define T_TMASK        (T_INT|T_CHR|T_DBL|T_LBL)
  137.  
  138. /* variable table */
  139. #define VLSIZ    150
  140.  
  141. struct label {
  142.     char *name;            /* what do we call it by. */
  143.     int (*where)();        /* and where does it live */
  144. };
  145. /* For arrays, storage of them is defined as follows:
  146.  *
  147.  *   1st item: number of dimensions in array <NDIMS>.
  148.  *   next <NDIMS> items: size of each dimension.
  149.  *   rest of items: the actual values.
  150.  *
  151.  * Until we can support varrying sized arrays this is the setup:
  152.  *
  153.  *   1,10,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10
  154.  *
  155.  * for a total size of 13 items.
  156.  */
  157. union value {
  158.     long ival;        /* T_INT */
  159.     double rval;    /* T_DBL */
  160.     char *sval;        /* T_CHR */
  161.     struct label lval;  /* T_LBL */
  162.     struct line *locval; /* for pushing line# list entries */
  163.     union value *arval; /* any+Q_ARY */
  164.     struct dictnode *vpval; /* for use when pushing variable pointers */
  165.     union value *plval; /* for use when pushing pointers to a value */
  166. };
  167.  
  168. struct dictnode {    /* format of vlist entry */
  169.     struct dictnode *father,*daughter;    /* doubly-linked list. */
  170.     char *name;        /* name of entry. */
  171.     int type_of_value;    /* its type. */
  172.     union value val;    /* and its value */
  173. };
  174.  
  175. extern struct dictnode *dicthead,*dictail,*curvp;
  176.  
  177. /* '_' Function table */
  178. extern
  179.     _print(),      _goto(),    _if(),        _else(),
  180.     _for(),        _next(),    _read(),    _data(),
  181.     _dsep(),    _spop(),    _pop(),        _stop(),
  182.     _end(),        _dlabel(),    _rlabel(),    _contin(),
  183.     _leave(),    _enter(),    _exitlp(),    _iadd(),
  184.     _isub(),    _imult(),    _idiv(),    _imod(),
  185.     _comma(),    _radd(),    _rsub(),    _rmult(),
  186.     _rdiv(),    _scolon(),    _gosub(),    _return(),
  187.     _not(),        _ieq(),        _req(),        _seq(),
  188.     _ineq(),    _rneq(),    _sneq(),    _ileq(),
  189.     _rleq(),    _sleq(),    _ilt(),        _rlt(),
  190.     _slt(),        _igeq(),    _rgeq(),    _sgeq(),
  191.     _igt(),        _rgt(),        _sgt(),        _or(),
  192.     _and(),        _itoa(),    _rtoa(),    _itor(),
  193.     _rtoi(),    _pushstate(),    _popstate(),    _scon(),
  194.     _rcon(),    _icon(),    _val(),        _store(),
  195.     _var();
  196.  
  197. /*
  198.  * Data table.
  199.  * Array of pointers into llist.
  200.  * Each is a line which has data.
  201.  */
  202. #define DLSIZ    100
  203. extern struct line *dlist[]; /* actual table, number of elems. is DLSIZ */
  204. extern int dlp;        /* index into dlist for current line of data */
  205. extern int dlindx;    /* index into current line for current data item. */
  206. extern int dtype;    /* in M_READ, operators set this to the type of 
  207.              * their operation.  When the expression is done
  208.              * executing, this variable will indicate its type.
  209.              */
  210.  
  211. /* error routines */
  212. extern int ULerror();
  213. extern int STerror();
  214. extern int FNerror();
  215. extern int ODerror();
  216. extern int BDerror();
  217. extern int VTerror();
  218.  
  219.  
  220. /*
  221.  * unions for storing data types in the code list 
  222.  *
  223.  * Used to convert from a double (for instance) into "int" sized chunks
  224.  * for the purpose of manipulating instances of them in code lists.
  225.  */
  226.  
  227.  
  228. union doni {
  229.     double d_in_doni;
  230.     int i_in_doni[sizeof(double)/sizeof(int)];
  231. };
  232. union loni {
  233.     long l_in_loni;
  234.     int i_in_loni[sizeof(long)/sizeof(int)];
  235. };
  236. union voni {
  237.     union value v_in_voni;
  238.     int i_in_voni[sizeof(union value)/sizeof(int)];
  239. };
  240.  
  241.  
  242. /* miscellaneous definitions. */
  243.  
  244. #define STKSIZ    500
  245. extern union value stack[];
  246. extern int stackp;
  247. extern int push();
  248. extern union value pop();
  249.  
  250. #define CSTKSIZ    5
  251. #define BFSIZ    200    /* input buffer */
  252. extern char pbbuf[];    /* unput() buffer */
  253. extern char ibuf[];
  254. extern int iptr,pbptr;
  255. extern char input();
  256. extern rdlin(),unput();
  257.  
  258. extern blcpy();
  259.  
  260. extern char bslash();
  261. extern char *scon_in();
  262. extern int num_in();
  263.  
  264. extern char *myalloc();
  265. extern union value *getplace();
  266. extern struct line *gllentry();
  267.  
  268. extern FILE *bsin;
  269.  
  270. extern int dbg;        /* debugging flag. */
  271. extern long atol();
  272. extern double atof();
  273. SHAR_EOF
  274. if test 4648 -ne "`wc -c < 'newbs/bsdefs.h'`"
  275. then
  276.     echo shar: error transmitting "'newbs/bsdefs.h'" '(should have been 4648 characters)'
  277. fi
  278. fi # end of overwriting check
  279. echo shar: extracting "'newbs/bsgram.y'" '(8891 characters)'
  280. if test -f 'newbs/bsgram.y'
  281. then
  282.     echo shar: will not over-write existing file "'newbs/bsgram.y'"
  283. else
  284. sed 's/^X//' << \SHAR_EOF > 'newbs/bsgram.y'
  285.     /* bsgram.y -- grammer specification for bs.
  286.      */
  287. %{
  288. #include "bsdefs.h"
  289.  
  290. char *p;        /* the generic pointer */
  291. int i;            /* the generic counter */
  292. int (*l[300])();    /* array to generate the code list into. */
  293. int lp;            /* pointer to current spot in l[] */
  294.  
  295. struct stk {
  296.     int stack[40];
  297.     int stkp;
  298. };
  299.  
  300. struct stk ifstk,whstk,forstk,repstk,lpstk;
  301. int gomax=0, ifmax=0, whmax=0, formax=0, repmax=0, lpmax=0;
  302.  
  303. extern char *yytext;
  304. extern char *bsyysval;
  305. extern int yyleng;
  306. %}
  307.  
  308. %term EQUAL    NEQ    LE    LT    GE    WHILE
  309. %term GT    OR    AND    NOT    RET    REPEAT
  310. %term IF    THEN    ELSE    GOTO    GOSUB    UNTIL
  311. %term STOP    END    INTEGER    REAL    SCONST    ELIHW
  312. %term LET    SWORD    PRINT    INPUT    DATA    CFOR
  313. %term FOR    TO    STEP    READ    WRITE    NEXT
  314. %term DEFINE    LFUN    SFUN    FDEF    SYMBOL    DIM
  315. %term VALUE    IWORD    RWORD    ROFC    LOOP    EXITIF
  316. %term ITOR    RTOI    ITOA    RTOA    LEAVE    CONTINUE
  317. %term POOL
  318.  
  319. %left ',' ';'
  320. %right '='
  321. %nonassoc OR AND
  322. %nonassoc LE LT GE GT EQUAL NEQ
  323. %left '+' '-'
  324. %left '*' '/' '%'
  325. %left UNARY
  326. %left '('
  327.  
  328.  
  329. %start lines
  330.  
  331. %%
  332.  
  333. lines        : /* empty */
  334.         | lines line
  335.         ;
  336.  
  337. line        : lnum stat '\n'
  338.             { printf("\n"); }
  339.         | '\n'
  340.         ;
  341.  
  342. lnum        : INTEGER
  343.             { bundle(2,_line,atoi($1); }
  344.         ;
  345.  
  346. stat        : LET let_xpr
  347.         | let_xpr
  348.         | PRINT pe
  349.             { bundle(1,_print); }
  350.         | GOTO INTEGER
  351.             {
  352.                 sprintf(s,"LN%s",$2);
  353.                 bundle(4,_rlabel,gvadr(s,T_LBL),_goto,0);
  354.             }
  355.         | GOSUB INTEGER
  356.             {
  357.                 sprintf(s,"LN%s",$2);
  358.                 bundle(4,_rlabel,gvadr(s,T_LBL),_gosub,0); 
  359.             }
  360.         | LEAVE
  361.             { bundle(2,_leave,0); }
  362.         | CONTINUE
  363.             { bundle(2,_contin,0); }
  364.         | RET
  365.             { bundle(1,_return); }
  366.         | IF bexpr
  367.             {
  368.                 lpush(&ifstk,ifmax);
  369.                 sprintf(s,"IF%d",ifmax);
  370.                 bundle(4,_rlabel,gvadr(s,T_LBL),_if,0);
  371.                 ifmax += 2;
  372.             }
  373.           THEN stat
  374.             {
  375.                 i = ltop(&ifstk);
  376.                 sprintf(s,"IF%d",i+1);
  377.                 bundle(4,_rlabel,gvadr(s,T_LBL),_goto,0);
  378.             }
  379.           if_else
  380.         | INPUT 
  381.             { bundle(2,_pushstate,M_INPUT); }
  382.           var_lst
  383.             { bundle(1,_popstate); }
  384.         | STOP
  385.             { bundle(1,_stop); }
  386.         | END
  387.             { bundle(1,_end); }
  388.         | FOR nvar '=' rexpr TO rexpr for_step
  389.             {
  390.                 lpush(&forstk,formax);
  391.                 sprintf(s,"FOR%d",formax+2);
  392.                 bundle(2,_rlabel,gvadr(s,T_LBL));
  393.                 sprintf(s,"FOR%d",formax+1);
  394.                 bundle(3,_rlabel,gvadr(s,T_LBL),_enter);
  395.                 sprintf(s,"FOR%d",formax+1);
  396.                 bundle(5,_icon,(long)0,_rlabel,gvadr(s,T_LBL));
  397.                 sprintf(s,"FOR%d",formax);
  398.                 bundle(4,_dlabel,gvadr(s,T_LBL),_for,0);
  399.                 formax += 3;
  400.             }
  401.         | NEXT
  402.             {
  403.                 i = ltop(&forstk);
  404.                 sprintf(s,"FOR%d",i+2);
  405.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  406.             }
  407.           nvar
  408.             {
  409.                 i = lpop(&forstk);
  410.                 sprintf(s,"FOR%d",i);
  411.                 bundle(5,_next,_rlabel,gvadr(s,T_LBL),_goto,0);
  412.                 sprintf(s,"FOR%d",i+1);
  413.                 bundle(3,_dlabel,gvadr(s,T_LBL),_exitlp);
  414.             }
  415.         | READ 
  416.             { bundle(2,_pushstate,M_READ); }
  417.           var_lst
  418.             { bundle(1,_popstate); }
  419.         | DATA 
  420.             { bundle(2,_data,0); }
  421.            data_lst
  422.         | LOOP
  423.             {
  424.                 lpush(&lpstk,lpmax);
  425.                 sprintf(s,"LP%d",lpmax+2);
  426.                 bundle(2,_rlabel,gvadr(s,T_LBL));
  427.                 sprintf(s,"LP%d",lpmax+1);
  428.                 bundle(3,_rlabel,gvadr(s,T_LBL),_enter);
  429.                 sprintf(s,"LP%d",lpmax);
  430.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  431.                 lpmax += 3;
  432.             }
  433.         | EXITIF bexpr
  434.             {
  435.                 i = ltop(&lpstk);
  436.                 sprintf(s,"LP%d",i+1);
  437.                 bundle(5,_not,_rlabel,gvadr(s,T_LBL),_if,0);
  438.             }
  439.         | POOL
  440.             {
  441.                 i = lpop(&lpstk);
  442.                 sprintf(s,"LP%d",i+2);
  443.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  444.                 sprintf(s,"LP%d",i);
  445.                 bundle(4,_rlabel,gvadr(s,T_LBL),_goto,0);
  446.                 sprintf(s,"LP%d",i+1);
  447.                 bundle(3,_dlabel,gvadr(s,T_LBL),_exitlp);
  448.             }
  449.         | WHILE
  450.             {
  451.                 lpush(&whstk,whmax);
  452.                 sprintf(s,"WH%d",whmax+2);
  453.                 bundle(2,_rlabel,gvadr(s,T_LBL));
  454.                 sprintf(s,"WH%d",whmax+1);
  455.                 bundle(3,_rlabel,gvadr(s,T_LBL),_enter);
  456.                 sprintf(s,"WH%d",whmax);
  457.                 bundle(2,_rlabel,gvadr(s,T_LBL));
  458.                 whmax += 3;
  459.             }
  460.           bexpr
  461.             {
  462.                 i = ltop(&whstk);
  463.                 sprintf(s,"WH%d",i+1);
  464.                 bundle(4,_rlabel,gvadr(s,T+LBL),_if,0);
  465.             }
  466.         | ELIHW
  467.             {
  468.                 i = lpop(&whstk);
  469.                 sprintf(s,"WH%d",i+2);
  470.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  471.                 sprintf(s,"WH%d",i)
  472.                 bundle(4,_rlabel,gvadr(s,T_LBL),_goto,0);
  473.                 sprintf(s,"WH%d",i+1);
  474.                 bundle(3,_dlabel,gvadr(s,T_LBL),_exitlp);
  475.             }
  476.         | REPEAT
  477.             {
  478.                 lpush(&repstk,repmax);
  479.                 sprintf(s,"REP%d",repmax+1);
  480.                 bundle(2,_rlabel,gvadr(s,T_LBL));
  481.                 sprintf(s,"REP%d",repmax+2);
  482.                 bundle(3,_rlabel,gvadr(s,T_LBL),_enter);
  483.                 sprintf(s,"REP%d",repmax);
  484.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  485.                 repmax += 3;
  486.             }
  487.         | UNTIL
  488.             {
  489.                 i = ltop(&repstk);
  490.                 sprintf(s,"REP%d",i+1);
  491.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  492.             }
  493.           bexpr
  494.             {
  495.                 i = lpop(&repstk);
  496.                 sprintf(s,"REP%d",i);
  497.                 bundle(5,_not,_rlabel,gvadr(s,T_LBL),_if,0);
  498.                 sprintf(s,"REP%d",i+2);
  499.                 bundle(3,_dlabel,gvadr(s,T_LBL),_exitlp);
  500.             }
  501.         ;
  502.  
  503. nvar        : ivar
  504.         | rvar
  505.         ;
  506.  
  507. let_xpr        : ivar '=' rexpr
  508.             { bundle(4,_rtoi,_store,T_DBL,_pop); }
  509.         | rvar '=' rexpr
  510.             { bundle(3,_store,T_DBL,_pop); }
  511.         | svar '=' sexpr
  512.             { bundle(3,_store,T_CHR,spop); }
  513.         ;
  514.  
  515. data_lst    : rexpr
  516.             { bundle(2,_dsep,0); }
  517.         | sexpr
  518.             { bundle(1,_dsep); }
  519.         | data_lst ',' rexpr
  520.             { bundle(1,_dsep); }
  521.         | data_lst ',' sexpr
  522.             { bundle(1,_dsep); }
  523.         ;
  524.  
  525. ind_lst        : rexpr
  526.         | ind_lst ',' rexpr
  527.         ;
  528.  
  529. for_step    : /* empty */
  530.             { bundle(3,_icon,(long)0); }
  531.         | STEP rexpr
  532.         ;
  533.  
  534. if_else        : /* empty */
  535.             {
  536.                 i = lpop(&ifstk);
  537.                 sprintf(s,"IF%d",i);
  538.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  539.                 sprintf(s,"IF%d",i+1);
  540.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  541.             }
  542.         | ELSE 
  543.             {
  544.                 i = ltop(&ifstk);
  545.                 sprintf(s,"IF%d",i);
  546.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  547.             }
  548.           stat
  549.             {
  550.                 i = lpop(&ifstk);
  551.                 sprintf(s,"IF%d",i+1);
  552.                 bundle(2,_dlabel,gvadr(s,T_LBL));
  553.             }
  554.         ;
  555.  
  556.  
  557. pe        : sexpr ','
  558.             { bundle(3,_scon,"",_comma); }
  559.         | sexpr ';'
  560.         | sexpr
  561.             { bundle(3,_scon,"\\n",_scolon); }
  562.         | /* empty */
  563.             { bundle(2,_scon,"\\n"); }
  564.         ;
  565.  
  566.  
  567. var_lst        : ivar
  568.         | rvar
  569.         | svar
  570.         | var_lst ',' var_lst
  571.         ;
  572.  
  573. sexpr        : SCONST
  574.             { p=myalloc(yyleng); strcpy(p,$1); bundle(2,_scon,p); }
  575.         | svar
  576.             { bundle(2,_val,T_CHR); }
  577.         | rexpr
  578.             { bundle(1,_rtoa); }
  579.         | svar '=' sexpr
  580.             { bundle(2,_store,T_CHR); }
  581.         | sexpr ';' sexpr
  582.             { bundle(1,_scolon); }
  583.         | sexpr '+' sexpr
  584.             { bundle(1,_scolon); }
  585.         | sexpr ',' sexpr
  586.             { bundle(1,_comma); }
  587.         | '(' sexpr ')'
  588.         ;
  589. sbe        : sexpr EQUAL sexpr
  590.             { bundle(1,_seq); }
  591.         | sexpr NEQ sexpr
  592.             { bundle(1,_sneq); }
  593.         | sexpr LE sexpr
  594.             { bundle(1,_sleq); }
  595.         | sexpr LT sexpr
  596.             { bundle(1,_slt); }
  597.         | sexpr GE sexpr
  598.             { bundle(1,_sgeq); }
  599.         | sexpr GT sexpr
  600.             { bundle(1,_sgt); }
  601.         ;
  602.  
  603. ivar        : IWORD
  604.             { bundle(2,_var,gvadr($1,T_INT)); }
  605.         | IWORD '(' 
  606.             { bundle(2,_pushstate,M_EXECUTE); }
  607.           ind_lst ')'
  608.             { bundle(3,_popstate,_var,gvadr($1,T_INT+Q_ARY)); }
  609.         ;
  610. rvar        : RWORD
  611.             { bundle(2,_var,gvadr($1,T_DBL)); }
  612.         | RWORD '(' 
  613.             { bundle(2,_pushstate,M_EXECUTE); }
  614.           ind_lst ')'
  615.             { bundle(3,_popstate,_var,gvadr($1,T_DBL+Q_ARY)); }
  616.         ;
  617.  
  618. svar        : SWORD
  619.             { bundle(2,_var,gvadr($1,T_CHR)); }
  620.         | SWORD '(' 
  621.             { bundle(2,_pushstate,M_EXECUTE); }
  622.           ind_lst ')'
  623.             { bundle(3,_popstate,_var,gvadr($1,T_CHR+Q_ARY)); }
  624.         ;
  625.  
  626.  
  627.  
  628. rexpr        : rvar
  629.             { bundle(2,_val,T_DBL); }
  630.         | REAL
  631.             { bundle(5,_rcon,(double)atof($1)); }
  632.         | INTEGER
  633.             { bundle(5,_rcon,(double)atof($1)); }
  634.         | ivar
  635.             { bundle(3,_val,T_INT,_itor); }
  636.         | rvar '=' rexpr
  637.             { bundle(2,_store,T_DBL); }
  638.         | '(' rexpr ')'
  639.         | rexpr '+' rexpr
  640.             { bundle(1,_radd); }
  641.         | rexpr '-' rexpr
  642.             { bundle(1,_rsub); }
  643.         | rexpr '*' rexpr
  644.             { bundle(1,_rmult); }
  645.         | rexpr '/' rexpr
  646.             { bundle(1,_rdiv); }
  647.         | '+' rexpr    %prec UNARY
  648.         | '-' rexpr    %prec UNARY
  649.             { bundle(6,_rcon,(double)(-1),_rmult); }
  650.         ;
  651.  
  652. rbe        : rexpr EQUAL rexpr
  653.             { bundle(1,_req); }
  654.         | rexpr NEQ rexpr
  655.             { bundle(1,_rneq); }
  656.         | rexpr LE rexpr
  657.             { bundle(1,_rleq); }
  658.         | rexpr LT rexpr
  659.             { bundle(1,_rlt); }
  660.         | rexpr GE rexpr
  661.             { bundle(1,_rgeq); }
  662.         | rexpr GT rexpr
  663.             { bundle(1,_rgt); }
  664.         ;
  665. bexpr        : sbe
  666.         | rbe
  667.         | NOT bexpr    %prec UNARY
  668.             { bundle(1,_not); }
  669.         | bexpr OR bexpr
  670.             { bundle(1,_or); }
  671.         | bexpr AND bexpr
  672.             { bundle(1,_and); }
  673.         | '(' bexpr ')'
  674.         ;
  675. %%
  676.  
  677. main()
  678. {
  679.     rdlin(bsin);
  680.     return(yyparse());
  681. }
  682.  
  683. yyerror(s)
  684. char *s;
  685. {
  686.     fprintf(stderr,"%s\n",s);
  687. }
  688.  
  689. lpush(stack,val) struct stk *stack; int val;
  690. {
  691.     stack->stack[stack->stkp++] = val; 
  692. }
  693.  
  694. int ltop(stack) struct stk *stack;
  695.     return(stack->stack[stack->stkp-1]); 
  696. }
  697.  
  698. int lpop(stack) struct stk *stack;
  699.     return(stack->stack[--stack->stkp]); 
  700. }
  701.  
  702. /* bundle() -- append argument list to l[].  Idea tooken from bc.y.
  703.  *
  704.  * Usage:  bundle(cnt,arg,arg,...,arg)
  705.  *
  706.  * The "arg"'s can be anything.  "cnt" is a count of the number of integers
  707.  * it would take to hold all the args.
  708.  *
  709.  * e.g.  bundle(4,(double)a); is the correct count for a.
  710.  *
  711.  *    ******* NOTE *******
  712.  *
  713.  * This routine is machine dependant.  It depends on the way arguments are
  714.  * passed on the stack on the PDP-11 machines.  It may not work elsewhere.
  715.  */
  716. bundle(a)
  717. int a;
  718. {
  719.     register int *p;
  720.     register int sz;
  721.  
  722.     p = &a;
  723.     sz = *p++;
  724.     while(sz-- > 0) 
  725.     l[lp++] = *p++;
  726. }
  727. SHAR_EOF
  728. if test 8891 -ne "`wc -c < 'newbs/bsgram.y'`"
  729. then
  730.     echo shar: error transmitting "'newbs/bsgram.y'" '(should have been 8891 characters)'
  731. fi
  732. fi # end of overwriting check
  733. echo shar: extracting "'newbs/bslash.c'" '(567 characters)'
  734. if test -f 'newbs/bslash.c'
  735. then
  736.     echo shar: will not over-write existing file "'newbs/bslash.c'"
  737. else
  738. sed 's/^X//' << \SHAR_EOF > 'newbs/bslash.c'
  739. /* bslash() -- have seen '\', use input() to say what is actually wanted.
  740.  */
  741. char bslash()
  742. {
  743.     char text[8];
  744.     register char *s,c;
  745.     int v;
  746.  
  747.     c=input();
  748.     if(c == 'n') c='\n';
  749.     else if(c == 't') c='\t';
  750.     else if(c == 'b') c='\b';
  751.     else if(c == 'r') c='\r';
  752.     else if(c == 'f') c='\f';
  753.     else if(c>='0' && c<='7') { /* octal digit string */
  754.     s = &text[0];
  755.     *s++ = c;
  756.     c=input();
  757.     while(c>='0' && c<='7') {
  758.         *s++ = c;
  759.         c=input();
  760.     }
  761.     *s++ = '\0';
  762.     sscanf(text,"%o",&v);
  763.     c = (char) v;
  764.     }
  765.     else if(c=='\n') rdlin(bsin);
  766.     return(c);
  767. }
  768. SHAR_EOF
  769. if test 567 -ne "`wc -c < 'newbs/bslash.c'`"
  770. then
  771.     echo shar: error transmitting "'newbs/bslash.c'" '(should have been 567 characters)'
  772. fi
  773. fi # end of overwriting check
  774. echo shar: extracting "'newbs/bslib.c'" '(1553 characters)'
  775. if test -f 'newbs/bslib.c'
  776. then
  777.     echo shar: will not over-write existing file "'newbs/bslib.c'"
  778. else
  779. sed 's/^X//' << \SHAR_EOF > 'newbs/bslib.c'
  780. /* bslib.c -- subroutine library, routines useful anywhere.
  781.  */
  782.  
  783. #include "bsdefs.h"
  784.  
  785. XFILE *bsin = stdin;
  786.  
  787. /* blcpy -- copies a block of memory (l bytes) from s to d.
  788.  */
  789. blcpy(d,s,l)
  790. char *d,*s;
  791. int l;
  792. {
  793.     for(; l >= 0; (l--)) *(d++) = *(s++);
  794. }
  795.  
  796. /* Input routines.  These routines buffer input a line at a time into
  797.  * ibuf.  Unputted input goes to pbbuf, and gets read before things in
  798.  * ibuf, if anything in pbbuf.
  799.  */
  800.  
  801. char pbbuf[CSTKSIZ],ibuf[BFSIZ];
  802.  
  803. int iptr = -1;
  804. int pbptr = -1;
  805.  
  806. char input()
  807. {
  808.     if(pbptr > -1)
  809.     return(pbbuf[pbptr--]);
  810.     else {
  811.     if(ibuf[iptr] == '\0') rdlin(bsin);
  812.     if(ibuf[iptr]!='\0' && !feof(bsin))
  813.         return(ibuf[iptr++]);
  814.     else
  815.         return(0);
  816.     }
  817. }
  818.  
  819. rdlin(f) FILE *f;
  820. {
  821.     char c;
  822.  
  823.     iptr = 0;
  824.     for(c=fgetc(f); c!='\n' && c!=EOF; c=fgetc(f)) ibuf[iptr++] = c;
  825.     ibuf[iptr++] = c;
  826.     ibuf[iptr++] = '\0';
  827.     iptr = 0;
  828. }
  829.  
  830. unput(c) char c;
  831. { pbbuf[++pbptr] = c; }
  832.  
  833. /* myalloc() -- allocate, checking for out of memory.
  834.  */
  835. char *myalloc(nb)
  836. int nb;
  837. {
  838.     char *rval;
  839.     rval = malloc(nb);
  840. /*
  841.     printf("myalloc:tos:%o,rv:%o,nb:%d,e:%o\n",&rval,rval,nb,sbrk(0));
  842. */
  843.     if(rval == 0) {
  844.     fprintf(stderr,"myalloc: out of memory\n");
  845.     exit(1);
  846.     }
  847.     return(rval);
  848. }
  849.  
  850.  
  851.  
  852. /* Stack routines.  Very simple. */
  853.  
  854. union value stack[STKSIZ];
  855. int stackp = -1;
  856.  
  857. push(i) union value i;
  858. {
  859.     stack[++stackp] = i;
  860. }
  861.  
  862. union value pop()
  863. {
  864.     return(stack[stackp--]);
  865. }
  866.  
  867. /* Mark stack.  Also very simple. */
  868. int mstack[5];
  869. int mstkp = -1;
  870. mpush()
  871. { mstack[++mstkp] = stackp; }
  872. mpop()
  873. { stackp = mstack[mstkp--]; }
  874. SHAR_EOF
  875. if test 1553 -ne "`wc -c < 'newbs/bslib.c'`"
  876. then
  877.     echo shar: error transmitting "'newbs/bslib.c'" '(should have been 1553 characters)'
  878. fi
  879. fi # end of overwriting check
  880. echo shar: extracting "'newbs/getplace.c'" '(488 characters)'
  881. if test -f 'newbs/getplace.c'
  882. then
  883.     echo shar: will not over-write existing file "'newbs/getplace.c'"
  884. else
  885. sed 's/^X//' << \SHAR_EOF > 'newbs/getplace.c'
  886. /* getplace() -- get a pointer to place of value for vlist entry on top of stack
  887.  *    For arrays, getplace() expects the indexes to be on the stack as well.
  888.  *    The parser should properly arrange for this to happen.
  889.  */
  890. union value *getplace(dp)
  891. struct dictnode *dp;
  892. {
  893.     int qual;
  894.     union value ind,*place;
  895.  
  896.     qual = dp->type_of_value&T_QMASK;
  897.     if(qual == Q_ARY) {
  898.     ind = pop();
  899.     mpop();
  900.     place = & dp->val.arval[ind.ival+2];
  901.     }
  902.     else
  903.     place = & dp->val;
  904.     return(place);
  905. }
  906. SHAR_EOF
  907. if test 488 -ne "`wc -c < 'newbs/getplace.c'`"
  908. then
  909.     echo shar: error transmitting "'newbs/getplace.c'" '(should have been 488 characters)'
  910. fi
  911. fi # end of overwriting check
  912. echo shar: extracting "'newbs/gvadr.c'" '(911 characters)'
  913. if test -f 'newbs/gvadr.c'
  914. then
  915.     echo shar: will not over-write existing file "'newbs/gvadr.c'"
  916. else
  917. sed 's/^X//' << \SHAR_EOF > 'newbs/gvadr.c'
  918. /* gvadr() -- Get variable address from vlist, with type checking.
  919.  *    This routine allows numerous copies of same name as long as
  920.  *    all copies have different types.  Probably doesnt matter since
  921.  *    the parser does the type checking.
  922.  */
  923. struct dictnode *gvadr(s,ty)
  924. char *s;
  925. int ty;
  926. {
  927.     register int i;
  928.     register int qual; /* type qualifier */
  929.  
  930.     /* Inefficient */
  931.     for(i=0; vlist[i].name!=0 && i<VLSIZ; i++)
  932.     if(vlist[i].type_of_value==ty && strcmp(s,vlist[i].name)==0)
  933.         /* match found */
  934.             break;
  935.     if(i >= VLSIZ) {
  936.     fprintf(stderr,"gvadr: out of room in variable list for %s\n",s);
  937.     exit(1);
  938.     }
  939.     /* not on list, enter it */
  940.     if(vlist[i].name == 0) {
  941.     vlist[i].name = myalloc(strlen(s)+1);
  942.     strcpy(vlist[i].name,s);
  943.     vlist[i].val.rval = 0;
  944.     vlist[i].type_of_value = ty;
  945.     if(ty&T_QMASK == Q_ARY)
  946.         vlist[i].val.arval = myalloc(13*sizeof(union value));
  947.     }
  948.     return(&vlist[i]);
  949. }
  950. SHAR_EOF
  951. if test 911 -ne "`wc -c < 'newbs/gvadr.c'`"
  952. then
  953.     echo shar: error transmitting "'newbs/gvadr.c'" '(should have been 911 characters)'
  954. fi
  955. fi # end of overwriting check
  956. echo shar: extracting "'newbs/makefile'" '(193 characters)'
  957. if test -f 'newbs/makefile'
  958. then
  959.     echo shar: will not over-write existing file "'newbs/makefile'"
  960. else
  961. sed 's/^X//' << \SHAR_EOF > 'newbs/makefile'
  962. operat2.o: mkop.sh op rop sop
  963.     mkop.sh >operat2.c
  964.     cc -c operat2.c
  965.     rm operat2.c
  966.     : done operat2.o
  967. op: mkop.c
  968.     cc mkop.c -o op
  969. rop: mkrbop.c
  970.     cc mkrbop.c -o rop
  971. sop: mksop.c
  972.     cc mksop.c -o sop
  973. SHAR_EOF
  974. if test 193 -ne "`wc -c < 'newbs/makefile'`"
  975. then
  976.     echo shar: error transmitting "'newbs/makefile'" '(should have been 193 characters)'
  977. fi
  978. fi # end of overwriting check
  979. echo shar: extracting "'newbs/makefile.old'" '(661 characters)'
  980. if test -f 'newbs/makefile.old'
  981. then
  982.     echo shar: will not over-write existing file "'newbs/makefile.old'"
  983. else
  984. sed 's/^X//' << \SHAR_EOF > 'newbs/makefile.old'
  985. OFILES = lex.o bsint.o action.o operat.o bslib.o errors.o
  986. PRSO= bsgram.o lex.o bslib.o
  987. INTO= bsint.o action.o operat2.o operat.o bslib.o errors.o
  988.  
  989. prs: ${PRSO}
  990.     cc -s ${PRSO} -o prs
  991. bsgram.o: bsgram.c bsdefs.h
  992.     cc -c bsgram.c
  993. bsgram.c: bsgram.y
  994.     yacc -d bsgram.y
  995.     mv y.tab.c bsgram.c
  996.     mv y.tab.h bstokens.h
  997.  
  998. int: ${INTO}
  999.     cc ${INTO} -o int
  1000.  
  1001. ${OFILES}: bsdefs.h
  1002.  
  1003. operat2.o: mkop.sh op rop sop
  1004.     mkop.sh >operat2.c
  1005.     cc -c operat2.c
  1006.     rm operat2.c
  1007.     : done operat2.o
  1008. op: mkop.c
  1009.     cc mkop.c -o op
  1010. rop: mkrbop.c
  1011.     cc mkrbop.c -o rop
  1012. sop: mksop.c
  1013.     cc mksop.c -o sop
  1014.  
  1015. pr:
  1016.     pr bsgram.y lex.c bsdefs.h bslib.c bsint.c action.c operat.c mkop.c mkrbop.c mksop.c errors.c | lpr
  1017. SHAR_EOF
  1018. if test 661 -ne "`wc -c < 'newbs/makefile.old'`"
  1019. then
  1020.     echo shar: error transmitting "'newbs/makefile.old'" '(should have been 661 characters)'
  1021. fi
  1022. fi # end of overwriting check
  1023. echo shar: extracting "'newbs/mkop.c'" '(1030 characters)'
  1024. if test -f 'newbs/mkop.c'
  1025. then
  1026.     echo shar: will not over-write existing file "'newbs/mkop.c'"
  1027. else
  1028. sed 's/^X//' << \SHAR_EOF > 'newbs/mkop.c'
  1029. /* mkop.c -- make operator function for bs.
  1030. *
  1031. *    USAGE: op name type oper tag
  1032. *
  1033. * where:    name: name of function generated.
  1034. *        type: data type of operation.
  1035. *        oper: operator for operation.
  1036. *        tag: structure tag name.
  1037. *
  1038. * This will only work with T_INT and T_DBL operators, T_CHR operations
  1039. * do not boil down to a simple operation.
  1040. */
  1041. #include <stdio.h>
  1042.  
  1043. main(argc,argv)
  1044. char **argv;
  1045. int argc;
  1046. {
  1047. char *name,*type,*oper,*tag;
  1048.  
  1049. if(argc != 5) {
  1050.     fprintf(stderr,"arg count\n");
  1051.     exit(1);
  1052. }
  1053. name = argv[1]; type = argv[2]; oper = argv[3]; tag = argv[4];
  1054.  
  1055. printf("_%s(l,p)\n",name);
  1056. printf("int (*l[])(),p;\n");
  1057. printf("{\n");
  1058. printf("    union value rg1,rg2,result;\n");
  1059. printf("\n");
  1060. printf("    if((status&XMODE)==M_READ){ dtype=T_%s; goto EXEC;}\n",type);
  1061. printf("    if((status&XMODE) == M_EXECUTE) {\n");
  1062. printf("EXEC:\n");
  1063. printf("    rg2 = pop();\n");
  1064. printf("    rg1 = pop();\n");
  1065. printf("    result.%s = rg1.%s %s rg2.%s;\n",tag,tag,oper,tag);
  1066. printf("    push(result);\n");
  1067. printf("    }\n");
  1068. printf("    return(p);\n");
  1069. printf("}\n");
  1070. }
  1071. SHAR_EOF
  1072. if test 1030 -ne "`wc -c < 'newbs/mkop.c'`"
  1073. then
  1074.     echo shar: error transmitting "'newbs/mkop.c'" '(should have been 1030 characters)'
  1075. fi
  1076. fi # end of overwriting check
  1077. echo shar: extracting "'newbs/mkop.sh'" '(482 characters)'
  1078. if test -f 'newbs/mkop.sh'
  1079. then
  1080.     echo shar: will not over-write existing file "'newbs/mkop.sh'"
  1081. else
  1082. sed 's/^X//' << \SHAR_EOF > 'newbs/mkop.sh'
  1083. echo "/* operat2.c -- more operators for bs.  the ones that are all alike."
  1084. echo " */"
  1085. echo ""
  1086. echo "#include \"bsdefs.h\""
  1087. echo ""
  1088. op "radd" "DBL" "+" "rval" 
  1089. op "rsub" "DBL" "-" "rval" 
  1090. op "rmult" "DBL" "*" "rval" 
  1091. op "rdiv" "DBL" "/" "rval" 
  1092. rop "req" "=="
  1093. sop "seq" "=="
  1094. rop "rneq" "!="
  1095. sop "sneq" "!="
  1096. rop "rleq" "<="
  1097. sop "sleq" "<="
  1098. rop "rlt" "<"
  1099. sop "slt" "<"
  1100. rop "rgeq" ">="
  1101. sop "sgeq" ">="
  1102. rop "rgt" ">"
  1103. sop "sgt" ">"
  1104. op "or" "INT" "||" "ival" 
  1105. op "and" "INT" "&&" "ival" 
  1106. SHAR_EOF
  1107. if test 482 -ne "`wc -c < 'newbs/mkop.sh'`"
  1108. then
  1109.     echo shar: error transmitting "'newbs/mkop.sh'" '(should have been 482 characters)'
  1110. fi
  1111. chmod +x 'newbs/mkop.sh'
  1112. fi # end of overwriting check
  1113. echo shar: extracting "'newbs/mksop.c'" '(725 characters)'
  1114. if test -f 'newbs/mksop.c'
  1115. then
  1116.     echo shar: will not over-write existing file "'newbs/mksop.c'"
  1117. else
  1118. sed 's/^X//' << \SHAR_EOF > 'newbs/mksop.c'
  1119. /* mksop.c -- make string comparator functions for bs.
  1120. *
  1121. *    USAGE: op name oper
  1122. *
  1123. * where:    name: name of function generated.
  1124. *        oper: operator for operation.
  1125. */
  1126. #include <stdio.h>
  1127.  
  1128. main(argc,argv)
  1129. char **argv;
  1130. int argc;
  1131. {
  1132. char *name,*oper;
  1133.  
  1134. if(argc != 3) {
  1135.     fprintf(stderr,"arg count\n");
  1136.     exit(1);
  1137. }
  1138. name = argv[1]; oper = argv[2];
  1139.  
  1140. printf("_%s(l,p)\n",name);
  1141. printf("int (*l[])(),p;\n");
  1142. printf("{\n");
  1143. printf("    union value rg1,rg2,result;\n");
  1144. printf("\n");
  1145. printf("    if((status&XMODE) == M_EXECUTE) {\n");
  1146. printf("    rg2 = pop();\n");
  1147. printf("    rg1 = pop();\n");
  1148. printf("    result.sval = strcmp(rg1.sval,rg2.sval) %s 0;\n",oper);
  1149. printf("    push(result);\n");
  1150. printf("    }\n");
  1151. printf("    return(p);\n");
  1152. printf("}\n");
  1153. }
  1154. SHAR_EOF
  1155. if test 725 -ne "`wc -c < 'newbs/mksop.c'`"
  1156. then
  1157.     echo shar: error transmitting "'newbs/mksop.c'" '(should have been 725 characters)'
  1158. fi
  1159. fi # end of overwriting check
  1160. echo shar: extracting "'newbs/num_ins.c'" '(3393 characters)'
  1161. if test -f 'newbs/num_ins.c'
  1162. then
  1163.     echo shar: will not over-write existing file "'newbs/num_ins.c'"
  1164. else
  1165. sed 's/^X//' << \SHAR_EOF > 'newbs/num_ins.c'
  1166. /* int_in() -- tokenizer routine for inputting a number.
  1167.  * int_in() returns a pointer to a static data area.  This area gets 
  1168.  * overwritten with each call to int_in so use the data before calling
  1169.  * int_in() again.
  1170.  */
  1171. char * int_in()
  1172. {
  1173.     register char c,*s;
  1174.     static char text[20];
  1175.  
  1176.     s = &text[0];
  1177.  
  1178. /* beginning state, skip junk until either '-' or ['0'-'9'] comes along */
  1179.  
  1180. l1: c=input();
  1181.     if(c>='0' && c<='9') goto l3;
  1182.     else if(c == '-') goto l2;
  1183.     else {
  1184.     if(c=='\n' || c=='\0') rdlin(bsin);
  1185.     goto l1;
  1186.     }
  1187.  
  1188. /* skipped junk, seen '-', gather it and make sure next char is a digit */
  1189.  
  1190. l2: *s++ = c;
  1191.     c=input();
  1192.     if(c==' ' || c=='\t') goto l2; /* allow white between sign and digit */
  1193.     else if(c>='0' && c<='9') goto l3;
  1194.     else { /* seen something not allowed. */
  1195.     s = &text[0];
  1196.     printf("\n\007??");
  1197.     goto l1; /* restart machine */
  1198.     }
  1199.  
  1200. /* skipped junk, seen a digit, gather until a non-digit appears */
  1201.  
  1202. l3: *s++ = c;
  1203.     c=input();
  1204.     if(c>='0' && c<='9') goto l3;
  1205.     else {
  1206.     /* have reached successful conclusion to machine. */
  1207.     unput(c);
  1208.     *s++ = '\0';
  1209.     return(text);
  1210.     }
  1211. }
  1212.  
  1213. /* real_in() -- read in a floating point number using input().
  1214.  *
  1215.  * real_in() returns a pointer to a static data area.  This data area
  1216.  * gets overwritten with each call to real_in(), so use it quickly.
  1217.  */
  1218. char *real_in()
  1219. {
  1220.     register char *s,c;
  1221.     static char bf[30];
  1222.  
  1223.     s = &bf[0];
  1224.  
  1225. /* starting state.  loops back until something interesting seen */
  1226.  
  1227. state1:    c=input();
  1228.     if(c == '-') goto state3;
  1229.     else if(c>='0' && c<='9') goto state2;
  1230.     else if(c == '.') goto state4;
  1231.     else {
  1232.         if(c == '\0') return(0);
  1233.         /* else */
  1234.         if(c == '\n') rdlin(bsin);
  1235.         goto state1;
  1236.     }
  1237.  
  1238. /* seen ([sign] dig). loop back for digs, looking for (.|e|E) */
  1239.  
  1240. state2: *s++ = c;
  1241.     c=input();
  1242.     if(c>='0' && c<='9') goto state2;
  1243.     else if(c=='e' || c=='E') goto state6;
  1244.     else if(c == '.') goto state4;
  1245.     else goto state9;    /* done */
  1246.  
  1247. /* seen (sign).  looking for (dig). ignore whitespace. */
  1248.  
  1249. state3: *s++ = c;
  1250. state3_a: c=input();
  1251.     if(c==' ' || c=='\t') goto state3_a;
  1252.     else if(c>='0' && c<='9') goto state2;
  1253.     else if(c == '.') goto state4;
  1254.     else goto state10;    /* error, had a sign so we have to have digs. */
  1255.  
  1256. /* seen ([sign] digs '.').  looking for digs.  done on anything else */
  1257.  
  1258. state4: *s++ = c;
  1259.     c=input();
  1260.     if(c>='0' && c<='9') goto state5;
  1261.     else goto state9;    /* done */
  1262.  
  1263. /* seen ([sign] digs '.' dig).  looking for (dig|e|E). done on anything else */
  1264.  
  1265. state5:    *s++ = c;
  1266.     c=input();
  1267.     if(c=='e' || c=='E') goto state6;
  1268.     else if(c>='0' && c<='9') goto state5;
  1269.     else goto state9;
  1270.  
  1271. /* seen ([sign] digs '.' digs (e|E)). looking for sign or digs, else error. */
  1272.  
  1273. state6: *s++ = c;
  1274.     c=input();
  1275.     if(c=='+' || c=='-') goto state7;
  1276.     else if(c>='0' && c<='9') goto state8;
  1277.     else goto state10;    /* error */
  1278.  
  1279. /* seen ([sign] digs '.' digs (e|E) sign). looking for digs, else error. */
  1280.  
  1281. state7: *s++ = c;
  1282.     c=input();
  1283.     if(c>='0' && c<='9') goto state8;
  1284.     else goto state10;    /* error */
  1285.  
  1286. /* seen ([sign] digs '.' digs (e|E) [sign] dig). looking for digs. */
  1287.  
  1288. state8: *s++ = c;
  1289.     c=input();
  1290.     if(c>='0' && c<='9') goto state8;
  1291.     else goto state9;    /* done */
  1292.  
  1293. /* seen a complete number.  machine successfully completed.  whew! */
  1294.  
  1295. state9: unput(c);    /* might want that later */
  1296.     *s++ = '\0';
  1297.     return(bf);
  1298.  
  1299. /* Uh oh.  An error.  Print an error and restart. */
  1300.  
  1301. state10: printf("\n\007??");
  1302.     s = &bf[0];
  1303.     goto state1;
  1304. }
  1305. SHAR_EOF
  1306. if test 3393 -ne "`wc -c < 'newbs/num_ins.c'`"
  1307. then
  1308.     echo shar: error transmitting "'newbs/num_ins.c'" '(should have been 3393 characters)'
  1309. fi
  1310. fi # end of overwriting check
  1311. echo shar: extracting "'newbs/op2.c'" '(4171 characters)'
  1312. if test -f 'newbs/op2.c'
  1313. then
  1314.     echo shar: will not over-write existing file "'newbs/op2.c'"
  1315. else
  1316. sed 's/^X//' << \SHAR_EOF > 'newbs/op2.c'
  1317. /* operat2.c -- more operators for bs.  the ones that are all alike.
  1318.  */
  1319.  
  1320. #include "bsdefs.h"
  1321.  
  1322. _radd(l,p)
  1323. int (*l[])(),p;
  1324. {
  1325.     union value rg1,rg2,result;
  1326.  
  1327.     if((status&XMODE)==M_READ){ dtype=T_DBL; goto EXEC;}
  1328.     if((status&XMODE) == M_EXECUTE) {
  1329. EXEC:
  1330.     rg2 = pop();
  1331.     rg1 = pop();
  1332.     result.rval = rg1.rval + rg2.rval;
  1333.     push(result);
  1334.     }
  1335.     return(p);
  1336. }
  1337. _rsub(l,p)
  1338. int (*l[])(),p;
  1339. {
  1340.     union value rg1,rg2,result;
  1341.  
  1342.     if((status&XMODE)==M_READ){ dtype=T_DBL; goto EXEC;}
  1343.     if((status&XMODE) == M_EXECUTE) {
  1344. EXEC:
  1345.     rg2 = pop();
  1346.     rg1 = pop();
  1347.     result.rval = rg1.rval - rg2.rval;
  1348.     push(result);
  1349.     }
  1350.     return(p);
  1351. }
  1352. _rmult(l,p)
  1353. int (*l[])(),p;
  1354. {
  1355.     union value rg1,rg2,result;
  1356.  
  1357.     if((status&XMODE)==M_READ){ dtype=T_DBL; goto EXEC;}
  1358.     if((status&XMODE) == M_EXECUTE) {
  1359. EXEC:
  1360.     rg2 = pop();
  1361.     rg1 = pop();
  1362.     result.rval = rg1.rval * rg2.rval;
  1363.     push(result);
  1364.     }
  1365.     return(p);
  1366. }
  1367. _rdiv(l,p)
  1368. int (*l[])(),p;
  1369. {
  1370.     union value rg1,rg2,result;
  1371.  
  1372.     if((status&XMODE)==M_READ){ dtype=T_DBL; goto EXEC;}
  1373.     if((status&XMODE) == M_EXECUTE) {
  1374. EXEC:
  1375.     rg2 = pop();
  1376.     rg1 = pop();
  1377.     result.rval = rg1.rval / rg2.rval;
  1378.     push(result);
  1379.     }
  1380.     return(p);
  1381. }
  1382. _req(l,p)
  1383. int (*l[])(),p;
  1384. {
  1385.     union value rg1,rg2,result;
  1386.  
  1387.     if((status&XMODE) == M_EXECUTE) {
  1388.     rg2 = pop();
  1389.     rg1 = pop();
  1390.     result.ival = rg1.rval == rg2.rval;
  1391.     push(result);
  1392.     }
  1393.     return(p);
  1394. }
  1395. _seq(l,p)
  1396. int (*l[])(),p;
  1397. {
  1398.     union value rg1,rg2,result;
  1399.  
  1400.     if((status&XMODE) == M_EXECUTE) {
  1401.     rg2 = pop();
  1402.     rg1 = pop();
  1403.     result.sval = strcmp(rg1.sval,rg2.sval) == 0;
  1404.     push(result);
  1405.     }
  1406.     return(p);
  1407. }
  1408. _rneq(l,p)
  1409. int (*l[])(),p;
  1410. {
  1411.     union value rg1,rg2,result;
  1412.  
  1413.     if((status&XMODE) == M_EXECUTE) {
  1414.     rg2 = pop();
  1415.     rg1 = pop();
  1416.     result.ival = rg1.rval != rg2.rval;
  1417.     push(result);
  1418.     }
  1419.     return(p);
  1420. }
  1421. _sneq(l,p)
  1422. int (*l[])(),p;
  1423. {
  1424.     union value rg1,rg2,result;
  1425.  
  1426.     if((status&XMODE) == M_EXECUTE) {
  1427.     rg2 = pop();
  1428.     rg1 = pop();
  1429.     result.sval = strcmp(rg1.sval,rg2.sval) != 0;
  1430.     push(result);
  1431.     }
  1432.     return(p);
  1433. }
  1434. _rleq(l,p)
  1435. int (*l[])(),p;
  1436. {
  1437.     union value rg1,rg2,result;
  1438.  
  1439.     if((status&XMODE) == M_EXECUTE) {
  1440.     rg2 = pop();
  1441.     rg1 = pop();
  1442.     result.ival = rg1.rval <= rg2.rval;
  1443.     push(result);
  1444.     }
  1445.     return(p);
  1446. }
  1447. _sleq(l,p)
  1448. int (*l[])(),p;
  1449. {
  1450.     union value rg1,rg2,result;
  1451.  
  1452.     if((status&XMODE) == M_EXECUTE) {
  1453.     rg2 = pop();
  1454.     rg1 = pop();
  1455.     result.sval = strcmp(rg1.sval,rg2.sval) <= 0;
  1456.     push(result);
  1457.     }
  1458.     return(p);
  1459. }
  1460. _rlt(l,p)
  1461. int (*l[])(),p;
  1462. {
  1463.     union value rg1,rg2,result;
  1464.  
  1465.     if((status&XMODE) == M_EXECUTE) {
  1466.     rg2 = pop();
  1467.     rg1 = pop();
  1468.     result.ival = rg1.rval < rg2.rval;
  1469.     push(result);
  1470.     }
  1471.     return(p);
  1472. }
  1473. _slt(l,p)
  1474. int (*l[])(),p;
  1475. {
  1476.     union value rg1,rg2,result;
  1477.  
  1478.     if((status&XMODE) == M_EXECUTE) {
  1479.     rg2 = pop();
  1480.     rg1 = pop();
  1481.     result.sval = strcmp(rg1.sval,rg2.sval) < 0;
  1482.     push(result);
  1483.     }
  1484.     return(p);
  1485. }
  1486. _rgeq(l,p)
  1487. int (*l[])(),p;
  1488. {
  1489.     union value rg1,rg2,result;
  1490.  
  1491.     if((status&XMODE) == M_EXECUTE) {
  1492.     rg2 = pop();
  1493.     rg1 = pop();
  1494.     result.ival = rg1.rval >= rg2.rval;
  1495.     push(result);
  1496.     }
  1497.     return(p);
  1498. }
  1499. _sgeq(l,p)
  1500. int (*l[])(),p;
  1501. {
  1502.     union value rg1,rg2,result;
  1503.  
  1504.     if((status&XMODE) == M_EXECUTE) {
  1505.     rg2 = pop();
  1506.     rg1 = pop();
  1507.     result.sval = strcmp(rg1.sval,rg2.sval) >= 0;
  1508.     push(result);
  1509.     }
  1510.     return(p);
  1511. }
  1512. _rgt(l,p)
  1513. int (*l[])(),p;
  1514. {
  1515.     union value rg1,rg2,result;
  1516.  
  1517.     if((status&XMODE) == M_EXECUTE) {
  1518.     rg2 = pop();
  1519.     rg1 = pop();
  1520.     result.ival = rg1.rval > rg2.rval;
  1521.     push(result);
  1522.     }
  1523.     return(p);
  1524. }
  1525. _sgt(l,p)
  1526. int (*l[])(),p;
  1527. {
  1528.     union value rg1,rg2,result;
  1529.  
  1530.     if((status&XMODE) == M_EXECUTE) {
  1531.     rg2 = pop();
  1532.     rg1 = pop();
  1533.     result.sval = strcmp(rg1.sval,rg2.sval) > 0;
  1534.     push(result);
  1535.     }
  1536.     return(p);
  1537. }
  1538. _or(l,p)
  1539. int (*l[])(),p;
  1540. {
  1541.     union value rg1,rg2,result;
  1542.  
  1543.     if((status&XMODE)==M_READ){ dtype=T_INT; goto EXEC;}
  1544.     if((status&XMODE) == M_EXECUTE) {
  1545. EXEC:
  1546.     rg2 = pop();
  1547.     rg1 = pop();
  1548.     result.ival = rg1.ival || rg2.ival;
  1549.     push(result);
  1550.     }
  1551.     return(p);
  1552. }
  1553. _and(l,p)
  1554. int (*l[])(),p;
  1555. {
  1556.     union value rg1,rg2,result;
  1557.  
  1558.     if((status&XMODE)==M_READ){ dtype=T_INT; goto EXEC;}
  1559.     if((status&XMODE) == M_EXECUTE) {
  1560. EXEC:
  1561.     rg2 = pop();
  1562.     rg1 = pop();
  1563.     result.ival = rg1.ival && rg2.ival;
  1564.     push(result);
  1565.     }
  1566.     return(p);
  1567. }
  1568. SHAR_EOF
  1569. if test 4171 -ne "`wc -c < 'newbs/op2.c'`"
  1570. then
  1571.     echo shar: error transmitting "'newbs/op2.c'" '(should have been 4171 characters)'
  1572. fi
  1573. fi # end of overwriting check
  1574. echo shar: extracting "'newbs/operat.c'" '(8663 characters)'
  1575. if test -f 'newbs/operat.c'
  1576. then
  1577.     echo shar: will not over-write existing file "'newbs/operat.c'"
  1578. else
  1579. sed 's/^X//' << \SHAR_EOF > 'newbs/operat.c'
  1580. /* operat.c -- operations, as opposed to actions.  FOR is an action,
  1581.  *    '+' is an operation.
  1582.  *
  1583.  * More operators can be found in the machine generated file "operat2.c".
  1584.  */
  1585.  
  1586. #include "bsdefs.h"
  1587.  
  1588.  
  1589. /*    BINARY OPERATORS    */
  1590.  
  1591. /* Common description for the binary ops.
  1592.  *  also applies to all ops in operat2.c
  1593.  *
  1594.  * M_COMPILE:
  1595.  *    x op x   --to--   x,_op,x
  1596.  * M_EXECUTE:
  1597.  *    stack: ar2,ar1,x   --to--   (ar1 op ar2),x
  1598.  */
  1599.  
  1600.  
  1601. _comma(l,p) int (*l[])(),p;
  1602. {
  1603.     union value s1,s2,s3;
  1604.     if((status&XMODE) == M_FIXUP) return(p);
  1605.     if((status&XMODE) == M_READ) { dtype = T_CHR; goto EXEC; }
  1606.     if((status&XMODE) == M_EXECUTE) {
  1607. EXEC:
  1608.         s1 = pop();
  1609.         s2 = pop();
  1610.         s3.sval = myalloc(strlen(s1.sval)+strlen(s2.sval)+3);
  1611.         strcpy(s3.sval,s2.sval);
  1612.         strcat(s3.sval,"\t");
  1613.         strcat(s3.sval,s1.sval);
  1614.         if(s1.sval != 0) free(s1.sval);
  1615.         if(s2.sval != 0) free(s2.sval);
  1616.         push(s3);
  1617.     }
  1618.         return(p);
  1619. }
  1620. _scolon(l,p) int(*l[])(),p;
  1621. {
  1622.     union value s1,s2,s3;
  1623.     if((status&XMODE) == M_READ) { dtype = T_CHR; goto EXEC; }
  1624.     if((status&XMODE) == M_EXECUTE) {
  1625. EXEC:
  1626.         s1 = pop();
  1627.         s2 = pop();
  1628.         s3.sval = myalloc(strlen(s1.sval)+strlen(s2.sval)+2);
  1629.         strcpy(s3.sval,s2.sval);
  1630.         strcat(s3.sval,s1.sval);
  1631.         push(s3);
  1632.         if(s1.sval != 0) free(s1.sval);
  1633.         if(s2.sval != 0) free(s2.sval);
  1634.     }
  1635.     return(p);
  1636. }
  1637. /* last of binary operators */
  1638.  
  1639. /* ---And now for something completely different: a Unary Operator.
  1640.  *
  1641.  * M_COMPILE:
  1642.  *    x not x    --to--    x,_not,x
  1643.  * M_EXECUTE:
  1644.  *    stack: bool,x    --to--     !(bool),x
  1645.  */
  1646. _not(l,p) int (*l[])(),p;
  1647. {
  1648.     union value val;
  1649.  
  1650.     if((status&XMODE) == M_EXECUTE) {
  1651.     val = pop();
  1652.     val.ival = ! val.ival;
  1653.     push(val);
  1654.     }
  1655.     return(p);
  1656. }
  1657.  
  1658. /* M_COMPILE:
  1659.  *    x itoa x   --to--   x,_itoa,x
  1660.  * M_EXECUTE:
  1661.  *    stack: int,x   --to--   string,x
  1662.  */
  1663. _itoa(l,p)
  1664. int (*l[])(),p;
  1665. {
  1666.     union value val;
  1667.     char s2[30];
  1668.  
  1669.     if((status&XMODE) == M_READ) { dtype = T_CHR; goto EXEC; }
  1670.     if((status&XMODE) == M_EXECUTE) {
  1671. EXEC:
  1672.         val=pop();
  1673.         sprintf(s2,"%D",val.ival);    /* optimize later */
  1674. if(dbg) printf("_icon():M_EXECUTE:ival:%D to sval:%s\n",val.ival,s2);
  1675.         val.sval=myalloc(strlen(s2)+1);
  1676.         strcpy(val.sval,s2);
  1677.         push(val);
  1678.     }
  1679.     return(p);
  1680. }
  1681. _rtoa(l,p)
  1682. int (*l[])(),p;
  1683. {
  1684.     union value val;
  1685.     char s2[30];
  1686.  
  1687.     if((status&XMODE) == M_READ) { dtype = T_CHR; goto EXEC; }
  1688.     if((status&XMODE) == M_EXECUTE) {
  1689. EXEC:
  1690.         val = pop();
  1691.         sprintf(s2,"%g",val.rval);
  1692. if(dbg) printf("_rtoa():M_EXECUTE:rval:%g to sval:%s\n",val.rval,s2);
  1693.         val.sval = myalloc(strlen(s2)+1);
  1694.         strcpy(val.sval,s2);
  1695.         push(val);
  1696.     }
  1697.     return(p);
  1698. }
  1699. _itor(l,p)
  1700. int (*l[])(),p;
  1701. {
  1702.     union value v1,v2;
  1703.  
  1704.     if((status&XMODE) == M_READ) { dtype = T_DBL; goto EXEC; }
  1705.     if((status&XMODE) == M_EXECUTE) {
  1706. EXEC:
  1707.         v1 = pop();
  1708.         v2.rval = (double)v1.ival;
  1709.         push(v2);
  1710.     }
  1711.     return(p);
  1712. }
  1713. _rtoi(l,p)
  1714. int (*l[])(),p;
  1715. {
  1716.     union value v1,v2;
  1717.  
  1718.     if((status&XMODE) == M_READ) { dtype = T_INT; goto EXEC; }
  1719.     if((status&XMODE) == M_EXECUTE) {
  1720. EXEC:
  1721.         v1 = pop();
  1722.         v2.ival = (int)v1.rval;
  1723.         push(v2);
  1724.     }
  1725.     return(p);
  1726. }
  1727.  
  1728. /* M_COMPILE:
  1729.  *    x scon "quoted string" x   --to--   x,_scon,&string,x
  1730.  * M_EXECUTE:
  1731.  *    stack: x   --to--   string,x
  1732.  *    other: pushes a COPY of the string, not the original.
  1733.  */
  1734. _scon(l,p)
  1735. int (*l[])(),p;
  1736. {
  1737.     char *s,c;
  1738.     union value val;
  1739.     int i;
  1740.  
  1741.     if((status&XMODE) == M_FIXUP) ++p;
  1742.     if((status&XMODE) == M_READ) { dtype = T_CHR; goto EXEC; }
  1743.     if((status&XMODE) == M_EXECUTE) {
  1744. EXEC:
  1745.         s = l[p++];
  1746.         val.sval = myalloc(strlen(s)+1);
  1747.         strcpy(val.sval,s);
  1748.         push(val);
  1749. if(dbg) printf("_scon():M_EXECUTE:sval:%s\n",val.sval);
  1750.     }
  1751.     return(p);
  1752. }
  1753.  
  1754. /* M_COMPILE:
  1755.  *    x icon int x   --to--   x,_icon,int,x
  1756.  * M_EXECUTE:
  1757.  *    stack: x   --to--   int,x
  1758.  */
  1759. _icon(l,p)
  1760. int (*l[])(),p;
  1761. {
  1762.     union value val;
  1763.     union loni v;
  1764.     int i;
  1765.  
  1766.     if((status&XMODE) == M_FIXUP) return(p+(sizeof(long)/sizeof(int)));
  1767.     if((status&XMODE) == M_READ) { dtype = T_INT; goto EXEC; }
  1768.     if((status&XMODE) == M_EXECUTE) {
  1769. EXEC:
  1770.         for(i=0; i<(sizeof(long)/sizeof(int)); i++)
  1771.         v.i_in_loni[i] = l[p++];
  1772.         val.ival = v.l_in_loni;
  1773.         push(val);
  1774. if(dbg) printf("_icon():M_EXECUTE:ival:%D\n",val.ival);
  1775.     }
  1776.     return(p);
  1777. }
  1778. _rcon(l,p)
  1779. int (*l[])(),p;
  1780. {
  1781.     union doni v;
  1782.     int i;
  1783.     union value val;
  1784.  
  1785.     if((status&XMODE) == M_FIXUP) return(p+(sizeof(double)/sizeof(int)));
  1786.     if((status&XMODE) == M_READ) { dtype = T_DBL; goto EXEC; }
  1787.     if((status&XMODE) = M_EXECUTE) {
  1788. EXEC:
  1789.         for(i=0; i<(sizeof(double)/sizeof(int)); i++)
  1790.         v.i_in_doni[i] = l[p++];
  1791.         val.rval = v.d_in_doni;
  1792.         push(val);
  1793.     }
  1794.     return(p);
  1795. }
  1796.  
  1797. /* M_COMPILE:
  1798.  *    x val type x   --to--   x,_val,type,x
  1799.  * M_EXECUTE:
  1800.  *    stack:    place,x   --to--   value,x
  1801.  *    other: for strings, pushes a copy of the string.
  1802.  */
  1803. _val(l,p) int(*l[])(),p;
  1804. {
  1805.     union value place,val;
  1806.     int ty;
  1807.  
  1808.     if((status&XMODE) == M_READ) { dtype = l[p]; goto EXEC; }
  1809.     if((status&XMODE) == M_EXECUTE) {
  1810. EXEC:
  1811.         ty = l[p];
  1812.         place = pop();
  1813. if(dbg) printf("_val():M_EXECUTE:var:%s",place.vpval->name);
  1814.         place.plval = getplace(place.vpval);
  1815.         if(ty==T_CHR && place.plval->sval!=0) {
  1816.         val.sval = myalloc(strlen(place.plval->sval)+1);
  1817.         strcpy(val.sval,place.plval->sval);
  1818.         push(val);
  1819.         }
  1820.         else push(*place.plval);
  1821. if(dbg) printf(":ival:%D:rval:%g:sval:%s\n",ty==T_INT?place.plval->ival:(long)0,
  1822.     ty==T_DBL?place.plval->rval:(double)0,ty==T_CHR?place.plval->sval:0);
  1823.     }
  1824.     return(p+1);
  1825. }
  1826.  
  1827. /* M_COMPILE:
  1828.  *    x store typ x   --to--    x,_store,type,x
  1829.  * M_EXECUTE:
  1830.  *    stack: value,location,x   --to--   value,x
  1831.  *        (stores value at location).
  1832.  */
  1833. _store(l,p) int(*l[])(),p;
  1834. {
  1835.     union value place,val;
  1836.     int ty;
  1837.  
  1838.     if((status&XMODE) == M_READ) { dtype = l[p]; goto EXEC; }
  1839.     if((status&XMODE) == M_EXECUTE) {
  1840. EXEC:
  1841.         val = pop();
  1842.         place = pop();
  1843.         ty = l[p];
  1844. if(dbg) printf("_store():M_EXECUTE:var:%s:ival:%D:rval:%g:sval:%s\n",
  1845.     place.vpval->name,ty==T_INT?val.ival:(long)0,ty==T_DBL?val.rval:(double)0,ty==T_CHR?val.sval:0);
  1846.         place.plval = getplace(place.vpval);
  1847.         if(ty==T_CHR && place.plval->sval!=0) free(place.plval->sval);
  1848.         (*place.plval) = val;
  1849.         push(val);
  1850.     }
  1851.     return(p+1);
  1852. }
  1853.  
  1854. /* M_COMPILE:
  1855.  *    x var typ name x   --to--    x,_var,&vlist entry,x
  1856.  * M_EXECUTE:
  1857.  *    stack: x   --to--   &vlist entry,x
  1858.  * M_INPUT:
  1859.  *    (&vlist entry)->val is set to input value.
  1860.  * M_READ:
  1861.  *    Moves the data list pointers to the next data item.  If no next
  1862.  *    data item, calls ODerror.
  1863.  *    Does a "gosub" to the data item, to get its value on the stack.
  1864.  *    Does T_INT to T_CHR conversion if necessary.
  1865.  *    Pops value into vp->val.
  1866.  */
  1867. _var(l,p) int(*l[])(),p; /* same proc for any variable type */
  1868. {
  1869.     char *s;
  1870.     struct dictnode *vp;
  1871.     struct line *thislist;
  1872.     union value place,val;
  1873.     int ty,qual;
  1874.  
  1875.     if((status&XMODE) == M_EXECUTE) {
  1876.         val.vpval = l[p++];
  1877. if(dbg) printf("_var():M_EXECUTE:var:(%d)%s\n",val.vpval->type_of_value,
  1878.     val.vpval->name);
  1879.         push(val);
  1880.         return(p);
  1881.     }
  1882.     if((status&XMODE) == M_INPUT) {
  1883.         vp = l[p++];
  1884.         place.plval = getplace(vp);
  1885.         ty = (vp->type_of_value) & T_TMASK;
  1886.         if(ty == T_INT)
  1887.         place.plval->ival = atol(int_in());
  1888.         else if(ty == T_DBL)
  1889.         place.plval->rval = atof(real_in());
  1890.         else /* ty == T_CHR */
  1891.         place.plval->sval = scon_in();
  1892. if(dbg) printf("_var():M_INPUT:var:(%d)%s:ival:%D:rval:%g:sval:%s\n",
  1893. vp->type_of_value,vp->name,ty==T_INT?place.plval->ival:(long)0,
  1894. ty==T_DBL?place.plval->rval:(double)0,ty==T_CHR?place.plval->sval:0);
  1895.         return(p);
  1896.     }
  1897.     if((status&XMODE) == M_READ) {
  1898. nxdl:        if(dlist[dlp] == 0) ODerror(l,p);    /* ran off end of dlist */
  1899.         thislist = dlist[dlp];
  1900.         if((thislist->code)[dlindx] == 0) {
  1901.         dlp++;
  1902.         dlindx = 2;    /* skips <_data,0> */
  1903.         goto nxdl;
  1904.         }
  1905.  
  1906.         status = M_EXECUTE;
  1907.         dlindx = interp(thislist->code,dlindx);
  1908.         status = M_READ;
  1909.  
  1910.         val = pop();
  1911.         vp = l[p];
  1912.         place.plval = getplace(vp);
  1913.         qual = vp->type_of_value&T_TMASK;
  1914.         if(qual == T_INT) {
  1915.         if(dtype == T_DBL) {
  1916.             push(val); _rtoi(l,p); val = pop();
  1917.         }
  1918.         place.plval->ival = val.ival;
  1919.         }
  1920.         else if(qual == T_DBL) {
  1921.         if(dtype == T_INT) {
  1922.             push(val); _itor(l,p); val = pop();
  1923.         }
  1924.         place.plval->rval = val.rval;
  1925.         }
  1926.         else if(qual == T_CHR) {
  1927.         if(dtype == T_INT) {
  1928.             push(val); _itoa(l,p); val = pop();
  1929.         }
  1930.         else if(dtype == T_DBL) {
  1931.             push(val); _rtoa(l,p); val = pop();
  1932.         }
  1933.         if(place.plval->sval != 0) free(place.plval->sval);
  1934.         place.plval->sval = myalloc(strlen(val.sval)+1);
  1935.         strcpy(place.plval->sval,val.sval);
  1936.         }
  1937.         else VTerror(l,p);
  1938.     return(p+1);
  1939.     }
  1940.     return(p+1);
  1941. }
  1942. SHAR_EOF
  1943. if test 8663 -ne "`wc -c < 'newbs/operat.c'`"
  1944. then
  1945.     echo shar: error transmitting "'newbs/operat.c'" '(should have been 8663 characters)'
  1946. fi
  1947. fi # end of overwriting check
  1948. echo shar: extracting "'newbs/scon_in.c'" '(1454 characters)'
  1949. if test -f 'newbs/scon_in.c'
  1950. then
  1951.     echo shar: will not over-write existing file "'newbs/scon_in.c'"
  1952. else
  1953. sed 's/^X//' << \SHAR_EOF > 'newbs/scon_in.c'
  1954. /* scon_in() -- read in a string constant using input.
  1955.  *    Format of an scon is either a quoted string, or a sequence
  1956.  *    of characters ended with a seperator (' ', '\t' or '\n' or ',').
  1957.  *
  1958.  *    In either mode, you can get funny characters into the string by
  1959.  *    "quoting" them with a '\'.
  1960.  *
  1961.  * scon_in() uses myalloc() to create space to store the string in.
  1962.  */
  1963. char *scon_in()
  1964. {
  1965.     register char c,*s;
  1966.     static char text [80];
  1967.  
  1968.     s = &text[0];
  1969.  
  1970. /* beginning state, skip seperators until something interesting comes along */
  1971.  
  1972. l1: c=input();
  1973.     if(c == '"') goto l2;
  1974.     else if(c=='\n' || c=='\0') {
  1975.     rdlin(bsin);
  1976.     goto l1;
  1977.     }
  1978.     else if(c==' ' || c=='\t' || c==',') goto l1;
  1979.     else goto l3;
  1980.  
  1981. /* have skipped unwanted material, seen a '"', read in a quoted string */
  1982.  
  1983. l2: c=input();
  1984.     if(c == '\n') {
  1985.     fprintf(stderr,"scon_in: unterminated string\n");
  1986.     exit(1);
  1987.     }
  1988.     else if(c == '\\') { *s++ = bslash(bsin); goto l2; }
  1989.     else if(c == '"')
  1990.     if((c=input()) == '"') {
  1991.         *s++ = '"';
  1992.         goto l2;
  1993.     }
  1994.     else goto done;
  1995.     else { *s++ = c; goto l2; }
  1996.  
  1997. /* skipped unwanted, seen something interesting, not '"', gather until sep */
  1998.  
  1999. l3: *s++ = c;
  2000.     c=input();
  2001.     if(c == '\\') { c = bslash(bsin); goto l3; }
  2002.     else if(c==' ' || c=='\t' || c==',' || c=='\n') goto done;
  2003.     else goto l3;
  2004.  
  2005. /* final state (if machine finished ok.) */
  2006.  
  2007. done: unput(c);
  2008.     *s++ = '\0';
  2009.     s=myalloc(strlen(text)+1);
  2010.     strcpy(s,text);
  2011.     return(s);
  2012. }
  2013. SHAR_EOF
  2014. if test 1454 -ne "`wc -c < 'newbs/scon_in.c'`"
  2015. then
  2016.     echo shar: error transmitting "'newbs/scon_in.c'" '(should have been 1454 characters)'
  2017. fi
  2018. fi # end of overwriting check
  2019. #    End of shell archive
  2020. exit 0
  2021.